package com.fr.data.impl;

import itsm.isperp.framework.core.context.ContextHolder;

import java.io.Serializable;
import java.sql.SQLException;

import javax.sql.DataSource;

import com.fr.data.pool.DBCPConnectionPoolAttr;
import com.fr.file.DatasourceManager;
import com.fr.general.ComparatorUtils;
import com.fr.general.Inter;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLableReader;

public class NameDatabaseConnection implements Connection, Serializable {
	private String name = null;
	protected transient java.sql.Connection _database = null;

	public NameDatabaseConnection() {
	}

	public NameDatabaseConnection(String paramString) {
		this.name = paramString;
	}

	public String getName() {
		return this.name;
	}

	public String getOriginalCharsetName() {
		return null;
	}

	public void setOriginalCharsetName(String paramString) {

	}

	public String getNewCharsetName() {
		return null;
	}

	public String getDriver() {
		return null;
	}

	public void setNewCharsetName(String paramString) {
	}

	public void testConnection() throws Exception {
	}

	public java.sql.Connection createConnection() throws Exception {
		return ((DataSource) ContextHolder.getSpringBean("dataSource"))
				.getConnection();
	}

	public boolean isDatabaseConnection() {
		try {
			return !createConnection().isClosed();
		} catch (Exception e) {
			return false;
		}
	}

	public boolean isXMLAConnection() {
		return false;
	}

	public boolean isFineBIConnection() {
		return false;
	}

	public int hashCode() {
		if (this.name != null)
			return this.name.hashCode();
		return 0;
	}

	public boolean equals(Object paramObject) {
		return ((paramObject instanceof NameDatabaseConnection))
				&& (ComparatorUtils.equals(getName(),
						((NameDatabaseConnection) paramObject).getName()));
	}

	public String toString() {
		return "[" + getName() + " Database]";
	}

	public void readXML(XMLableReader paramXMLableReader) {
		String str;
		if ((paramXMLableReader.isChildNode())
				&& ("DatabaseName".equals(paramXMLableReader.getTagName()))
				&& ((str = paramXMLableReader.getElementValue()) != null))
			this.name = str;
	}

	public void writeXML(XMLPrintWriter paramXMLPrintWriter) {
		if (getName() != null)
			paramXMLPrintWriter.startTAG("DatabaseName").textNode(getName())
					.end();
	}

	public Object clone() throws CloneNotSupportedException {
		return super.clone();
	}
}